#include "ShaderManager.h"

ShaderMan ShaderManager::shaders;

//
//	InitShaders
//
void ShaderManager::init() {

	Shader* flat = Shader::FromFilenames("../Shaders/default.vert.glsl", "../Shaders/flat.frag.glsl");
	add("flat_shader", flat);

};


//
//	DestroyShaders
//
void ShaderManager::destroy() {
	// Destruct all shader objects
	for(auto it = ShaderManager::shaders.begin(); it != ShaderManager::shaders.end(); ++it) {
		if(it->second != NULL) {
			delete it->second;
		}
	}
};


//
//	Add
//
void ShaderManager::add(string name, Shader* s) {
	ShaderManager::shaders.insert(std::make_pair<string, Shader*>(name, s));
};


//
//	Get
//
Shader* ShaderManager::get(string name) {

	ShaderMan::const_iterator got = shaders.find(name);

	if(got == shaders.end()) {
		// Shader not found
#ifdef NDEBUG
		// TODO : Return default shader?
#endif 
		return NULL;
	}

	return got->second;

};
